//
//  FileUtil.m
//  dataGathering
//
//  Created by macmini on 15/3/24.
//  Copyright (c) 2015年 shuili. All rights reserved.
//

#import "FileUtil.h"

static NSString* featureDataDirectory = @"/featureData";
static NSString* tpkDataDirectory = @"/TPK";

@implementation FileUtil
+(BOOL)checkIfFileDownloaded: (NSString*)filename :(FileType)fileType;
{
    NSFileManager* fm=[NSFileManager defaultManager];
    NSString *appDocumentPath = [NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *filePath;
    if(fileType == FileTypeFeatureData){
        filePath = [appDocumentPath stringByAppendingString:featureDataDirectory];
    } else if(fileType == FileTypeTPK){
        filePath = [appDocumentPath stringByAppendingString:tpkDataDirectory];
    }

    if (![fm fileExistsAtPath:filePath]) {
        NSLog(@"there is no Directory: %@",filePath);
        [fm createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
        return NO;
    }
    filePath = [filePath stringByAppendingString:@"/"];
    filePath = [filePath stringByAppendingString:filename];
    return [fm fileExistsAtPath:filePath];
}

+(void)deleteTPKFile:(NSString*)tpkName
{
    NSFileManager* fm=[NSFileManager defaultManager];
    NSString *appDocumentPath = [NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *filePath;
    filePath = [[[appDocumentPath stringByAppendingString:tpkDataDirectory] stringByAppendingPathComponent:tpkName] stringByAppendingString:@".tpk"];
    NSError *error;
    [fm removeItemAtPath:filePath error:&error];
    NSLog(@"remove tpk error is %@",error);
    
}

@end
